package com.itheima.contact.web;

import com.itheima.contact.domain.PageBean;
import com.itheima.contact.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author ${Azer}
 * @LOVE,,,
 * @Date 2021/9/19 20:06
 */
@WebServlet("/pageBeanServlet")
public class PageBeanServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取当前页数
        int curPage = Integer.parseInt(request.getParameter("curPage"));

//        System.out.println("当前页是："+curPage);

        //每一页显示几条数据
        int pageSize=3;
        //将数据传输到Service层，并将最后分页的数据封装到PageBean中
        UserService userService=new UserService();

        PageBean pageBean = userService.queryPageBean(curPage, pageSize);

        //将pageBean存储到request域对象中
        request.setAttribute("pb",pageBean);

        //转发到page.jsp页面
        request.getRequestDispatcher("/page.jsp").forward(request,response);
    }
}
